(function() {
	'use strict';
	
	var dir = STENCIL_PATH;
	var stepDefine = {};
	
	var stepStyleData  = {
	    image: {
	    	style: 'image;html=1;fontColor=#475669;labelTextOverflow=ellipsis;labelWidth=36;labelOverflow=hidden;labelBackgroundColor=transparent;image=../../../dacp-view/datastash/workshop/unit_creator/images/step/',
	    	width: 26,
	    	height: 26
	    },
	    swimlane: {
	    	style: 'swimlane;',
	    	width: 250,
	    	height: 200	
	    }
	}
	
	var createStep = function(step) {
		var stepStyle = step.stepStyle == 'image' ? stepStyleData[step.stepStyle].style + step.stepIcon + '.png' : stepStyleData[step.stepStyle].style;
		var type = step.stepStyle == 'image' ? 'step' : 'container';
		var width = stepStyleData[step.stepStyle].width;
		var height = stepStyleData[step.stepStyle].height;
		return editorUi.sidebar.createVertexTemplateEntry(stepStyle, width, height, step.stepInstLabel, step.stepInst, true, true, 'step', step.groupType, step.stepInst, type, true, true, true);
	}
	
	
	var getStepDefine = function() {
		axios.get(_contextPath + '/open/datastash/stepdefines')
		.then(function (response) {
		    var data = response.data,
		        stepData = {},
		        groupTypeOptions = {
	    			'controlCmd': '控制指令',
					'batchExtract': '批量抽取',
					'batchLoad': '批量加载',
					'batchTransfer': '批量转换',
					'rowLevelExtract': '行级抽取',
					'rowLevelLoad': '行级加载',
					'rowLevelTransfer': '行级转换',
					'check': '校验'
		        };

            for (var i in groupTypeOptions) {
            	stepData[i] = [];
            }
		    for (var i in data) {
		    	var type = data[i].groupType;
		    	stepDefine[data[i].stepInst] = data[i];
		    	if (type in stepData) {
		    		stepData[type].push(data[i]);
		    	}
		    }
		    
		    for (var i in stepData) {
		    	var stepGroup = [];
		    	for (var j in stepData[i]) {
		    		stepGroup.push(createStep(stepData[i][j]));
		    	}
		    	editorUi.sidebar.addPaletteFunctions(i, groupTypeOptions[i], true, stepGroup);
		    }
		})
		.catch(function (error) {
		    console.log(error);
		});
	}
	
	window.getStepDefine = getStepDefine;
	window.stepDefine = stepDefine;
}())